﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;

namespace CoderJoe.WoW.GearManager.Views
{
    /// <summary>
    /// Interaction logic for EquipmentButton.xaml
    /// </summary>
    public partial class EquipmentButton : UserControl
    {
        private Workspace m_workspace;
        [Dependency]
        public Workspace Workspace 
        {
            get
            {
                return m_workspace;
            }
            set
            {
                m_workspace = value;
                SetupLocalContainer();
            }
        }
        private IUnityContainer LocalContainer { get; set; }
        private CharacterItemModel Model { get { return (CharacterItemModel)DataContext; } }

        public EquipmentButton()
        {
            InitializeComponent();
        }

        private void SetupLocalContainer()
        {
            LocalContainer = m_workspace.CreateChildContainer();
            LocalContainer.RegisterType<ItemToolTipController>(new ContainerControlledLifetimeManager());
        }


        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Model.ItemId > 0)
            {
                ItemToolTipController toolTipController = LocalContainer.Resolve<ItemToolTipController>();
                toolTipController.Show(Model.ItemId, this);
            }
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            ItemToolTipController toolTipController = LocalContainer.Resolve<ItemToolTipController>();
            toolTipController.Hide();
        }
    }
}
